

import 'package:bt_tool/basic/bt_date_tool.dart';
import 'package:bt_tool/basic/bt_db_tool.dart';
import 'package:bt_tool/basic/bt_language_tool.dart';
import 'package:bt_tool/basic/bt_model.dart';
import 'package:flutter_demo/tools/project/project_define.dart';
import 'package:flutter_demo/tools/project/model/project_model.dart';

class ProjectTool {

  static createProjectTable() async {
    bool isTableExist = await BTDbTool.share().isTableExist(ProjectDefine.tableName);
    if(!isTableExist){
      await BTDbTool.share().createTable(ProjectDefine.tableName, [
        BTDbFieldModel("id", BTModelFieldType.intType,isAutoIncrement: true,isPrimaryKey: true),
        BTDbFieldModel("name", BTModelFieldType.stringType,isNotNull: true),
        BTDbFieldModel("createTime", BTModelFieldType.intType,isNotNull: true,defaultValue: "0"),
        BTDbFieldModel("translateConfig", BTModelFieldType.stringType,isNotNull: false),
        BTDbFieldModel("translateKey", BTModelFieldType.stringType,isNotNull: false),
        BTDbFieldModel("translateExportType", BTModelFieldType.intType,isNotNull: false,defaultValue: "0"),
      ]);
      ProjectModel model = ProjectModel(null);
      model.name = "默认项目".btTrans;
      model.createTime = BTDateTool.currentTimeSeconds();
      BTDbTool.share().insertData(ProjectDefine.tableName, model.convertToDictOnly(["name","createTime"]));
    }

    // await BTDbTool.share().alertTable(ProjectDefine.tableName, [BTDbFieldModel("translateExportType", BTModelFieldType.intType,isNotNull: false,defaultValue: "0"),]);

  }

   static Future<List<ProjectModel>> getProjectData() async {
    var dataResult = await BTDbTool.share().query(ProjectDefine.tableName,orderBy: "createTime DESC",);
    List<ProjectModel> modelList = [];
    for(var map in dataResult){
      modelList.add(ProjectModel(map));
    }
    return modelList;
  }

}